﻿
/******************************************
*Create Date : 2009 -12-18
*Description : program static function write here
********************************************/

var EnumAlarmType = {
    NoAlarm: 0x00,
    SOSButton_Pressed_Input1_Active: 0x01,
    ButtonB_Pressed_Input2_Active: 0x02,
    ButtonC_Pressed_Input3_Active: 0x03,
    Input4_Active: 0x04,
    Input5_Active: 0x05,
    LowBattery: 0x10,
    OverSpeed: 0x11,
    MovementAlarm: 0x12,
    GeoFenceAlarm: 0x13,
    TurnOnAlarm: 0x14,
    EnterGPSBlindAlarm: 0x15,
    ExitGPSBlindAlarm: 0x16,
    SOSButton_Released_Input1_InActive: 0x31,
    ButtonB_Released_Input2_InActive: 0x32,
    ButtonC_Released_Input3_InActive: 0x33,
    Input4_InActive: 0x34,
    Input5_InActive: 0x35,
    External_power_cut_alarm: 0x50,
    Veer_report: 0x52,
    GPS_Antenna_Cut: 0x53,

    Low_External_Power: 0x69,
    GeoFenceInAlarm: 0x70,
    GeoFenceOutAlarm: 0x71,
    External_Power_On: 0x72,
    External_Power_Off: 0x73,
    EnterSleep: 0x74,
    ExitSleep: 0x75,
    Antenna_Thefted: 0x76,
    Crashed: 0x77,
    HeartBeat: 0x78,
    DistanceReport: 0x79,
    DemondReport: 0x7A,
    IntervalReport: 0x7B,
    Tow: 0x7C,
    RFID: 0x7D,
    AskforAddress: 0x7E,
    PictureTaken: 0x7F,
    PowerOff: 0x28,
    Stay: 0x29,
    Moving: 0x2A,
    FuelAlarm: 0x2E,
    
    Fatigue_Driving_Alarm : 135,
    TemperatureHigh:200,
    TemperatureLow:201,
    FuelLow:202,
    FuelHigh:203,
    FuelDown:204,
    
    Warning:1001,
    GPS_Module_Err : 1003,
    GPS_Antenna_Shotted: 1004,
    LCD_Err : 1011,
    TTS_Err :1012,
    Camera_Err : 1013,
    DayDrivingOverTime : 1014,
    ParkingOverTime: 1015,
    RouteDriveTimeNotEnoughOrTooLong : 1016,
    VSS_Err : 1017,
    Fuel_Err: 1018,
    Stolen : 1019,
    IllegalACC : 1020,
    IllegalMoving: 1021,
    
    FarAwayRoute: 10001,
    CloseToRoute: 10002,
    InPolygonGeo: 10010,
    OutPolygonGeo:10011,
    GBAlarm:10100
};


function getCommandStringFromCommandID(commandid) {
    var s = "";
    switch (commandid) {
        case EnumGPRSCommand.Track_on_Demand:
        case EnumMT88Command.Track_on_Demand_only_for_GPRS:
            s = _CommandExpression_TrackOnDemand;
            break;
        case EnumGPRSCommand.Track_by_Interval:
        case 0x5100: // gt30,give 4012 command but get 5100
            s = _CommandExpression_SetGPRSInterval;
            break;
        case EnumGPRSCommand.Authorization:
            s = _CommandExpression_Authorization;
            break;
        case EnumGPRSCommand.Overspeed:
            s = _CommandExpression_SetOverSpeed;
            break;
        case EnumGPRSCommand.Movement_Alarm:
            s = _CommandExpression_SetMovementAlarm;
            break;
        case EnumGPRSCommand.GeoFence_In_Alarm:
        case EnumGPRSCommand.GeoFence_Out_Alarm:
            s = _CommandExpression_SetGeoFence;
            break;
        case EnumGPRSCommand.Extended_Settings:
            s = _CommandExpression_SetExtendedFunctions;
            break;
        case EnumGPRSCommand.Output_Control_Limited_Below10kmh_VTOnly:
        case EnumGPRSCommand.Output_Control_Limited_Below20kmh_VTOnly:
            s = _CommandExpression_Enginelimited;
            break;

        case EnumGPRSCommand.Output_Control_Unlimited_VTOnly:
            s = _CommandExpression_EngineUnlimited;
            break;
        case EnumGPRSCommand.Triggered_Alarms:
            s = _CommandExpression_TriggeredAlarms;
            break;
        case EnumGPRSCommand.Sleep_Mode:
            s = _CommandExpression_SetSleepMode;
            break;
        case EnumGPRSCommand.Listen:
            s = _CommandExpression_SetWiretapping;
            break;
        case EnumGPRSCommand.Time_Zone:
            s = _CommandExpression_SetTimeZone;
            break;
        case EnumGPRSCommand.Veer_Report:
        case EnumMT88Command.Track_on_course_change_only_for_GPRS:
            s = _CommandExpression_GPRS_SetVeerReport;
            break;
        case EnumGPRSCommand.Reboot_GPS:
            s = _CommandExpression_RebootGPS;
            break;
        case EnumGPRSCommand.GPS_Antenna_Cut:
            s = _CommandExpression_SetGPSAntennaAlarm;
            break;
        case EnumGPRSCommand.Heartbeat:
        case EnumMT88Command.Set_heart_beat_time_only_for_GPRS:
            s = _CommandExpression_GPRS_SetHeartBeat;
            break;
        case EnumGPRSCommand.Log_by_Interval:
            s = _CommandExpression_GPRS_SetLogInterval;
            break;
        case EnumGPRSCommand.Format:
            s = _CommandExpression_GPRS_FormatLoggedData;
            break;
        case EnumGPRSCommand.Read_Logged_Data:
            s = _CommandExpression_GPRS_ReadLoggedData;
            break;
        case EnumGPRSCommand.Read_Interval:
            s = _CommandExpression_GPRS_ReadInterval;
            break;
        case EnumGPRSCommand.Read_Authorization:
            s = _CommandExpression_ReadAuthorization;
            break;
        case EnumGPRSCommand.Get_SN_IMEI:
            s = _CommandExpression_ReasSNIMEIFirmware;
            break;
        case EnumMT88Command.Track_on_interval_and_counter_only_for_GPRS:
            s = _CommandExpression_SetIntervalCounter;
            break;
        case EnumMT88Command.Track_on_distance_interval:
            s = _CommandExpression_SetDistanceInverval;
            break;
        case EnumMT88Command.Set_GPRS:
            s = _CommandExpression_SetGPRS;
            break;
        case EnumMT88Command.Set_Second_GPRS_Server:
            s = _CommandExpression_SetSecondGPRS;
            break;
        case EnumMT88Command.Set_Authorize_phone_number_and_SMS_Event_Flag:
            s = _CommandExpression_SetAuthorizePhoneAndFlag;
            break;
        case EnumMT88Command.Get_Authorize_phone_number_and_SMS_Event_Flag:
            s = _CommandExpression_GetAuthorizePhoneAndFlag;
            break;
        case EnumMT88Command.Add_SMS_Event_Flag:
            s = _CommandExpression_SetSMSEventFlag;
            break;
        case EnumMT88Command.Delete_SMS_Event_Flag:
            s = _CommandExpression_DeleteSMSEventFlag;
            break;
        case EnumMT88Command.Set_Geo_fence_alert:
        case EnumMT88Command.Set_Geo_fence_alert_with_Name:
            s = _CommandExpression_SetGeoFence;
            break;
        case EnumMT88Command.Delete_Geo_fence_alert:
            s = _CommandExpression_DeleteGeoFence;
            break;
        case EnumMT88Command.Set_Speeding:
            s = _CommandExpression_SetOverSpeed;
            break;
        case EnumMT88Command.Set_tow_alert:
            s = _CommandExpression_SetTowAlert;
            break;
        case EnumMT88Command.Set_extended_functions:
            s = _CommandExpression_SetExtendedFunctions;
            break;
        case EnumMT88Command.Set_GPS_sleep_mode:
            s = _CommandExpression_SetGPSSleepMode;
            break;
        case EnumMT88Command.Set_go_into_sleep_time:
            s = _CommandExpression_SetSleepTime;
            break;
        case EnumMT88Command.Set_interval_for_logging:
            s = _CommandExpression_GPRS_SetLogInterval;
            break;
        case EnumMT88Command.Set_SMS_time_zone:
            s = _CommandExpression_SetSMSTimeZone;
            break;
        case EnumMT88Command.Set_SMS_Header_for_Event:
            s = _CommandExpression_SetSMSCommnadHeader;
            break;
        case EnumMT88Command.Set_Event_Flag_for_GPRS:
            s = _CommandExpression_SetEventFlagforGPRS;
            break;
        case EnumMT88Command.Get_Event_Flag_for_GPRS:
            s = _CommandExpression_GetEventFlagforGPRS;
            break;
        case EnumMT88Command.Output_control:
            s = _CommandExpression_Outputcontrol;
            break;
        case EnumMT88Command.Read_Firmware_version_and_SN:
            s = _CommandExpression_ReadFirmwareandSN;
            break;
        case EnumMT88Command.Reboot_GSM_module:
            s = _CommandExpression_RebootGSM;
            break;
        case EnumMT88Command.Reboot_GPS_module:
            s = _CommandExpression_RebootGPS;
            break;
        case EnumMT88Command.Initialize_parameters_except_for_password:
            s = _CommandExpression_Initialization;
            break;
        case EnumMT88Command.Initialize_password:
            s = _CommandExpression_PasswordInitialization;
            break;
        case EnumMT88Command.Change_Password:
            s = _CommandExpression_ChangePassword;
            break;
        case EnumMT88Command.Send_SMS_From_GPRS:
            s = _CommandExpression_SendSMSFromGPRS;
            break;
        case EnumMT88Command.Read_EEP_Data:
            s = _CommandExpression_ReadEEPData;
            break;
        case EnumMT88Command.Get_Image_Names:
            s = _CommandExpression_GetAllPictureName;
            break;
        case EnumMT88Command.Get_Image_Data:
            s = _CommandExpression_GetPictureByName;
            break;
        case EnumMT88Command.Set_Event_Flag_for_Taking_Picture:
            s = _CommandExpression_SetPhotoEventFlag;
            break;
        case EnumMT88Command.Get_Event_Flag_for_Taking_Picture:
            s = _CommandExpression_GetPhotoEventFlag;
            break;
        case EnumMT88Command.Take_Picture:
            s = _CommandExpression_TakePhoto;
            break;
        case EnumMT88Command.Delete_Pictures:
            s = _CommandExpression_DeletePicture;
            break;
        case EnumMT88Command.Stop_Picture_Sending:
            s = _CommandExpression_StopPictureData;
            break;
        case EnumMT88Command.GPRS_Message:
            s = _CommandExpression_GPRS_Message;
            break;
        case EnumMT88Command.Add_RFID:
            s = _CommandExpression_AuthRFID;
            break;
        case EnumMT88Command.Batch_Auth_RFID:
            s = _CommandExpression_BatchAuthRFID;
            break;
        case EnumMT88Command.Check_RFID_Auth:
            s = _CommandExpression_BatchDelRFID;
            break;
        case EnumMT88Command.Read_Authed_RFID:
            s = _CommandExpression_ReadAuthedRFID;
            break;
        case EnumMT88Command.Delete_Authed_RFID:
            s = _CommandExpression_DelAuthedRFID;
            break;
        case EnumMT88Command.Batch_Dele_Authed_RFID:
            s = _CommandExpression_BatchDelRFID;
            break;
        case EnumMT88Command.Set_Fuel_Alarm:
            s = _CommandExpression_SetFuelAlarm;
            break;
        default:
            
            break;
    }
    return s;
}

function getAlarmStringFromAlarmTypeExtend(alarmtype, sssid) {
    var a = parseInt(alarmtype);
    var s = getAlarmStringFromAlarmType(a);
    if(isInputAlarm(s)){
        if(g_DicTrackerAlarmDefine.ContainsKey(sssid)){
            if (g_DicTrackerAlarmDefine.Item(sssid).ContainsKey(a)) {
                var record = g_DicTrackerAlarmDefine.Item(sssid).Item(a);
                s = record.get('Expression');
            }
        };
    }
    return s;
}


function getAlarmStringFromAlarmType(alarmtype) {
    var s = "";
    var t = parseInt(alarmtype);
    switch (t) {
        case EnumAlarmType.NoAlarm:
        case 0x00:
            s = '';
            break;
        case EnumAlarmType.SOSButton_Pressed_Input1_Active:
        case 0x01:
            s = _AlarmResource_SOSButton_Pressed_Input1_Active;
            break;
        case EnumAlarmType.ButtonB_Pressed_Input2_Active:
        case 0x02:
            s = _AlarmResource_ButtonB_Pressed_Input2_Active;
            break;
        case EnumAlarmType.ButtonC_Pressed_Input3_Active:
        case 0x03:
            s = _AlarmResource_ButtonC_Pressed_Input3_Active;
            break;
        case EnumAlarmType.Input4_Active:
        case 0x04:
            s = _AlarmResource_Input4_Active;
            break;
        case EnumAlarmType.Input5_Active:
        case 0x05:
            s = _AlarmResource_Input5_Active;
            break;
        case EnumAlarmType.LowBattery:
        case 0x10:
            s = _AlarmResource_LowBattery;
            break;
        case EnumAlarmType.OverSpeed:
        case 0x11:
            s = _AlarmResource_OverSpeed;
            break;
        case EnumAlarmType.MovementAlarm:
        case 0x12:
            s = _AlarmResource_MovementAlarm;
            break;
        case EnumAlarmType.GeoFenceAlarm:
        case 0x13:
            s = _AlarmResource_GeoFenceAlarm;
            break;
        case EnumAlarmType.TurnOnAlarm:
        case 0x14:
            s = _AlarmResource_TurnOnAlarm;
            break;
        case EnumAlarmType.EnterGPSBlindAlarm:
        case 0x15:
            s = _AlarmResource_EnterGPSBlindAlarm;
            break;
        case EnumAlarmType.ExitGPSBlindAlarm:
        case 0x16:
            s = _AlarmResource_ExitGPSBlindAlarm;
            break;
        case EnumAlarmType.SOSButton_Released_Input1_InActive:
        case 0x31:
            s = _AlarmResource_SOSButton_Released_Input1_InActive;
            break;
        case EnumAlarmType.ButtonB_Released_Input2_InActive:
        case 0x32:
            s = _AlarmResource_ButtonB_Released_Input2_InActive;
            break;
        case EnumAlarmType.ButtonC_Released_Input3_InActive:
        case 0x33:
            s = _AlarmResource_ButtonC_Released_Input3_InActive;
            break;
        case EnumAlarmType.Input4_InActive:
        case 0x34:
            s = _AlarmResource_Input4_InActive;
            break;
        case EnumAlarmType.Input5_InActive:
        case 0x35:
            s = _AlarmResource_Input5_InActive;
            break;
        case EnumAlarmType.External_power_cut_alarm:
        case 0x50:
            s = _AlarmResource_External_power_cut_alarm;
            break;
        case EnumAlarmType.Veer_report:
        case 0x52:
            s = _AlarmResource_Veer_report;
            break;
        case EnumAlarmType.GPS_Antenna_Cut:
        case 0x53:
            s = _AlarmResource_GPSAntennaCut;
            break;
        case EnumAlarmType.Low_External_Power:
        case 0x69:
            s = _AlarmResource_LowExternalPower;
            break;
        case EnumAlarmType.GeoFenceInAlarm:
        case 0x70:
            s = _AlarmResource_EnterGeofence;
            break;
        case EnumAlarmType.GeoFenceOutAlarm:
        case 0x71:
            s = _AlarmResource_ExitGeofence;
            break;
        case EnumAlarmType.External_Power_On:
        case 0x72:
            s = _AlarmResource_ExternalPowerOn;
            break;
        case EnumAlarmType.External_Power_Off:
        case 0x73:
            s = _AlarmResource_ExternalPowerOff;
            break;
        case EnumAlarmType.EnterSleep:
        case 0x74:
            s = _AlarmResource_EnterSleep;
            break;
        case EnumAlarmType.ExitSleep:
        case 0x75:
            s = _AlarmResource_ExitSleep;
            break;
        case EnumAlarmType.Antenna_Thefted:
        case 0x76:
            //case 0x53:
            s = _AlarmResource_GPSAntennaCut;
            break;
        case EnumAlarmType.Crashed:
        case 0x77:
            s = _AlarmResource_Impact;
            break;
        case EnumAlarmType.HeartBeat:
        case 0x78:
            s = _AlarmResource_HeartbeatReport;
            break;
        case EnumAlarmType.DistanceReport:
        case 0x79:
            s = _AlarmResource_DistanceIntervalReport;
            break;
        case EnumAlarmType.DemondReport:
        case 0x7A:
            s = _AlarmResource_CurrentLocationReport;
            break;
        case EnumAlarmType.IntervalReport:
        case 0x7B:
            s = _AlarmResource_TimeIntervalReport;
            break;
        case EnumAlarmType.Tow:
        case 0x7C:
            s = _AlarmResource_TowAlarm;
            break;
        case EnumAlarmType.RFID:
        case 0x7D:
            s = _AlarmResource_RFID;
            break;
        case EnumAlarmType.AskforAddress:
        case 0x7E:
            s = _AlarmResource_AskforAddress;
            break;
        case EnumAlarmType.PictureTaken:
        case 0x7F:
            s = _AlarmResource_PictureTaken;
            break;
        
        case EnumAlarmType.PowerOff:
        case 0x28:
            s = _AlarmResource_PowerOff;
            break;
        case EnumAlarmType.Stay:
        case 0x29:
            s = _AlarmResource_Stay;
            break;
        case EnumAlarmType.Moving:
        case 0x2A:
            s = _AlarmResource_Moving;
            break;
        case EnumAlarmType.FuelAlarm:
        case 0x2E:
            s = _AlarmResource_FuelAlarm;
            break;
        case EnumAlarmType.Fatigue_Driving_Alarm:
        case 135:
            s = _AlarmResource_FatigueDrivingAlarm;
            break;
        case EnumAlarmType.TemperatureHigh:
        case 200:
            s= _AlarmResource_HighTemperature;
            break;
        case EnumAlarmType.TemperatureLow:
         case 201:
            s = _AlarmResource_LowTemperature;
            break;
        case EnumAlarmType.FuelLow:
        case 202:
            s = _AlarmResource_FuelLow;
            break;
        case EnumAlarmType.FuelHigh:
        case 203:
            s = _AlarmResource_FuelHigh;   
            break;
        case EnumAlarmType.FuelDown:
        case 204:
            s = _TrackerMain_FuelDown;
            break;
        case EnumAlarmType.Warning:
        case 1001:
            s = _AlarmResource_Warning;
            break;
        case EnumAlarmType.GPS_Module_Err:
        case 1003:
            s = _AlarmResource_GPS_Module_Err;
            break;
        case EnumAlarmType.GPS_Antenna_Shotted:
        case 1004:
            s = _AlarmResource_GPS_Module_Shotted;
            break;
        case EnumAlarmType.LCD_Err:
        case 1011:
            s = _AlarmResource_LCD_Err;
            break;
        case EnumAlarmType.TTS_Err:
        case 1012:
            s = _AlarmResource_TTS_Err;
            break;
        case EnumAlarmType.Camera_Err:
        case 1013:
            s = _AlarmResource_Camera_Err;
            break;
        case EnumAlarmType.DayDrivingOverTime:
        case 1014:
            s = _AlarmResource_DayDriving_Over_Time;
            break;
        case EnumAlarmType.ParkingOverTime:
        case 1015:
            s = _AlarmResource_Parking_Over_Time;
            break;
        case EnumAlarmType.RouteDriveTimeNotEnoughOrTooLong:
        case 1016:
            s = _AlarmResource_RouteDriveTimeNotEnoughOrTooLong;
            break;
        case EnumAlarmType.VSS_Err:
        case 1017:
            s = _AlarmResource_VSS_Err;
            break;
        case EnumAlarmType.Fuel_Err:
        case 1018:
            s = _AlarmResource_Fuel_Err;
            break;
        case EnumAlarmType.Stolen:
        case 1019:
            s = _AlarmResource_Stolen;
            break;
        case EnumAlarmType.IllegalACC:
        case 1020:
            s = _AlarmResource_Illegal_ACC;
            break;
        case EnumAlarmType.IllegalMoving:
        case 1021:
            s = _AlarmResource_Illegal_Moving;
            break;
        case EnumAlarmType.FarAwayRoute:
        case 10001:
            s = _AlarmResource_FarAwayRoute;
            break;
        case EnumAlarmType.CloseToRoute:
        case 10002:
            s = _AlarmResource_CloseToAlarm;
            break;
        case EnumAlarmType.InPolygonGeo:
        case 10010:
            s = _AlarmResource_InPolygonGeo;
            break;
        case EnumAlarmType.OutPolygonGeo:
        case 10011:
            s = _AlarmResource_OutPolygonGeo;
            break;
        default:
            s = t;
    }
    var m;
    for (m = 0; m < dymanicalarminfo.length; m++) {
        var ainfo = dymanicalarminfo[m];
        if (s == ainfo.alarmtype) {
            s = ainfo.expression;
        }
    }
    
    return s;
}

function getAlarmTypeFromAlarmString(alarmExpression) {
	//debugger;
    var alarm = EnumAlarmType.NoAlarm;
    if (alarmExpression == _AlarmResource_ButtonB_Pressed_Input2_Active)
        alarm = EnumAlarmType.ButtonB_Pressed_Input2_Active;
    else if (alarmExpression == _AlarmResource_ButtonB_Released_Input2_InActive)
        alarm = EnumAlarmType.ButtonB_Released_Input2_InActive;
    else if (alarmExpression == _AlarmResource_ButtonC_Pressed_Input3_Active)
        alarm = EnumAlarmType.ButtonC_Pressed_Input3_Active;
    else if (alarmExpression == _AlarmResource_ButtonC_Released_Input3_InActive)
        alarm = EnumAlarmType.ButtonC_Released_Input3_InActive;
    else if (alarmExpression == _AlarmResource_EnterGPSBlindAlarm)
        alarm = EnumAlarmType.EnterGPSBlindAlarm;
    else if (alarmExpression == _AlarmResource_ExitGPSBlindAlarm)
        alarm = EnumAlarmType.ExitGPSBlindAlarm;
    else if (alarmExpression == _AlarmResource_External_power_cut_alarm)
        alarm = EnumAlarmType.External_power_cut_alarm;
    else if (alarmExpression == _AlarmResource_GeoFenceAlarm)
        alarm = EnumAlarmType.GeoFenceAlarm;
    else if (alarmExpression == _AlarmResource_Input4_Active)
        alarm = EnumAlarmType.Input4_Active;
    else if (alarmExpression == _AlarmResource_Input4_InActive)
        alarm = EnumAlarmType.Input4_InActive;
    else if (alarmExpression == _AlarmResource_Input5_Active)
        alarm = EnumAlarmType.Input5_Active;
    else if (alarmExpression == _AlarmResource_Input5_InActive)
        alarm = EnumAlarmType.Input5_InActive;
    else if (alarmExpression == _AlarmResource_LowBattery)
        alarm = EnumAlarmType.LowBattery;
    else if (alarmExpression == _AlarmResource_MovementAlarm)
        alarm = EnumAlarmType.MovementAlarm;
    else if (alarmExpression == _AlarmResource_NoAlarm)
        alarm = EnumAlarmType.NoAlarm;
    else if (alarmExpression == _AlarmResource_OverSpeed)
        alarm = EnumAlarmType.OverSpeed;
    else if (alarmExpression == _AlarmResource_SOSButton_Pressed_Input1_Active)
        alarm = EnumAlarmType.SOSButton_Pressed_Input1_Active;
    else if (alarmExpression == _AlarmResource_SOSButton_Released_Input1_InActive)
        alarm = EnumAlarmType.SOSButton_Released_Input1_InActive;
    else if (alarmExpression == _AlarmResource_TurnOnAlarm)
        alarm = EnumAlarmType.TurnOnAlarm;
    else if (alarmExpression == _AlarmResource_Veer_report)
        alarm = EnumAlarmType.Veer_report;
    else if (alarmExpression == _AlarmResource_LowExternalPower)
        alarm = EnumAlarmType.Low_External_Power;
    else if (alarmExpression == _AlarmResource_EnterGeofence) {
        alarm = EnumAlarmType.GeoFenceInAlarm;
    }
    else if (alarmExpression == _AlarmResource_ExitGeofence) {
        alarm = EnumAlarmType.GeoFenceOutAlarm;
    }
    else if (alarmExpression == _AlarmResource_ExternalPowerOn) {
        alarm = EnumAlarmType.External_Power_On;
    }
    else if (alarmExpression == _AlarmResource_ExternalPowerOff) {
        alarm = EnumAlarmType.External_Power_Off;
    }
    else if (alarmExpression == _AlarmResource_EnterSleep) {
        alarm = EnumAlarmType.EnterSleep;
    }
    else if (alarmExpression == _AlarmResource_ExitSleep) {
        alarm = EnumAlarmType.ExitSleep;
    }
    else if (alarmExpression == _AlarmResource_GPSAntennaCut) {
        alarm = EnumAlarmType.Antenna_Thefted;
    }
    else if (alarmExpression == _AlarmResource_Impact) {
        alarm = EnumAlarmType.Crashed;
    }
    else if (alarmExpression == _AlarmResource_TowAlarm) {
        alarm = EnumAlarmType.Tow;
    }
    else if (alarmExpression == _AlarmResource_RFID) {
        alarm = EnumAlarmType.RFID;
    }
    else if (alarmExpression == _AlarmResource_AskforAddress) {
        alarm = EnumAlarmType.AskforAddress;
    }
    else if (alarmExpression == _AlarmResource_PictureTaken) {
        alarm = EnumAlarmType.PictureTaken;
    }
    else if (alarmExpression == _AlarmResource_FarAwayRoute) {
        alarm = EnumAlarmType.FarAwayRoute;
    }
    else if (alarmExpression == _AlarmResource_PowerOff) {
        alarm = EnumAlarmType.PowerOff;
    }
    else if (alarmExpression == _AlarmResource_Stay) {
        alarm = EnumAlarmType.Stay;
    }
    else if (alarmExpression == _AlarmResource_Moving) {
        alarm = EnumAlarmType.Moving;
    }
    else if (alarmExpression == _AlarmResource_CloseToAlarm) {
        alarm = EnumAlarmType.CloseToRoute;
    }
    else if (alarmExpression == _AlarmResource_InPolygonGeo) {
        alarm = EnumAlarmType.InPolygonGeo;
    }
    else if (alarmExpression == _AlarmResource_OutPolygonGeo) {
        alarm = EnumAlarmType.OutPolygonGeo;
    }
    else if (alarmExpression == _AlarmResource_FatigueDrivingAlarm) {
        alarm = EnumAlarmType.Fatigue_Driving_Alarm;
    }
    else if (alarmExpression == _AlarmResource_Warning) {
        alarm = EnumAlarmType.Warning;
    }
    else if (alarmExpression == _AlarmResource_GPS_Module_Err) {
        alarm = EnumAlarmType.GPS_Module_Err;
    }
    else if (alarmExpression == _AlarmResource_GPS_Module_Shotted) {
        alarm = EnumAlarmType.GPS_Antenna_Shotted;
    }
    else if (alarmExpression == _AlarmResource_LCD_Err) {
        alarm = EnumAlarmType.LCD_Err;
    }
    else if (alarmExpression == _AlarmResource_TTS_Err) {
        alarm = EnumAlarmType.TTS_Err;
    }
    else if (alarmExpression == _AlarmResource_Camera_Err) {
        alarm = EnumAlarmType.Camera_Err;
    }
    else if (alarmExpression == _AlarmResource_DayDriving_Over_Time) {
        alarm = EnumAlarmType.DayDrivingOverTime;
    }
    else if (alarmExpression == _AlarmResource_Parking_Over_Time) {
        alarm = EnumAlarmType.ParkingOverTime;
    }
    else if (alarmExpression == _AlarmResource_RouteDriveTimeNotEnoughOrTooLong) {
        alarm = EnumAlarmType.RouteDriveTimeNotEnoughOrTooLong;
    }
    else if (alarmExpression == _AlarmResource_VSS_Err) {
        alarm = EnumAlarmType.VSS_Err;
    }
    else if (alarmExpression == _AlarmResource_Fuel_Err) {
        alarm = EnumAlarmType.Fuel_Err;
    }
    else if (alarmExpression == _AlarmResource_Stolen) {
        alarm = EnumAlarmType.Stolen;
    }
    else if (alarmExpression == _AlarmResource_Illegal_ACC) {
        alarm = EnumAlarmType.IllegalACC;
    }
    else if (alarmExpression == _AlarmResource_Illegal_Moving) {
        alarm = EnumAlarmType.Moving;
    }
    else if (alarmExpression == _AlarmResource_Crashed) {
        alarm = EnumAlarmType.Crashed;
    }
    else if(alarmExpression == _AlarmResource_HighTemperature){
        alarm = EnumAlarmType.TemperatureHigh;
    } 
    else if(alarmExpression ==  _AlarmResource_LowTemperature){
        alarm = EnumAlarmType.TemperatureLow;
    }
    else if(alarmExpression == _AlarmResource_FuelLow){
        alarm =  EnumAlarmType.FuelLow;
    }
    else if(alarmExpression == _AlarmResource_FuelHigh){
        alarm = EnumAlarmType.FuelHigh;
    }
    else if(alarmExpression == _AlarmResource_FuelDown){
        alarm = EnumAlarmTyp.FuelDown;
    }
    var m;
    for (m = 0; m < dymanicalarminfo.length; m++) {
        var ainfo = dymanicalarminfo[m];
        if (alarmExpression == ainfo.expression) {
            alarmExpression = ainfo.alarmtype; //get original alarmtype
            alarm = getAlarmTypeFromAlarmString(alarmExpression);
            break;
        }

    }
    return alarm;
}

function hasEmergencyAlarm(alarmtype) {
    var hasEmergencyAlarm = false;
    var t = parseInt(alarmtype);
    switch (t) {
        
        case EnumAlarmType.External_power_cut_alarm:
        case EnumAlarmType.GeoFenceAlarm:
        case EnumAlarmType.LowBattery:
        case EnumAlarmType.MovementAlarm:
        case EnumAlarmType.OverSpeed:
        case EnumAlarmType.SOSButton_Pressed_Input1_Active:
        case EnumAlarmType.SOSButton_Released_Input1_InActive:
       
        case EnumAlarmType.Antenna_Thefted:
            //case EnumAlarmType.EnterGPSBlindAlarm:
            //case EnumAlarmType.ExitGPSBlindAlarm:
        case EnumAlarmType.Crashed:
        case EnumAlarmType.External_Power_Off:
        case EnumAlarmType.External_Power_On:
        case EnumAlarmType.GeoFenceInAlarm:
        case EnumAlarmType.GeoFenceOutAlarm:
        case EnumAlarmType.Low_External_Power:
        case EnumAlarmType.Tow:
        case EnumAlarmType.GPS_Antenna_Cut:
        //case EnumAlarmType.FallDown:
        case EnumAlarmType.FarAwayRoute:
        case EnumAlarmType.External_Power_Off:
        case EnumAlarmType.TurnOnAlarm:
        case EnumAlarmType.Veer_report:
        case EnumAlarmType.FuelAlarm:
        case EnumAlarmType.InPolygonGeo:
        case EnumAlarmType.OutPolygonGeo:
        case EnumAlarmType.Camera_Err:
        case EnumAlarmType.DayDrivingOverTime:
        case EnumAlarmType.Fatigue_Driving_Alarm:
        case EnumAlarmType.Fuel_Err:
        case EnumAlarmType.GPS_Module_Err:
        case EnumAlarmType.IllegalACC:
        case EnumAlarmType.IllegalMoving:
        case EnumAlarmType.LCD_Err:
        case EnumAlarmType.TTS_Err:
        case EnumAlarmType.Stolen:
        case EnumAlarmType.VSS_Err:
        case EnumAlarmType.Warning: 
        case EnumAlarmType.TemperatureHigh:
        case EnumAlarmType.TemperatureLow:
        case EnumAlarmType.FuelLow:
        case EnumAlarmType.FuelHigh:
        case EnumAlarmType.FuelDown:
            hasEmergencyAlarm = true;
            break;
        case EnumAlarmType.ButtonB_Pressed_Input2_Active:
        case EnumAlarmType.ButtonB_Released_Input2_InActive:
            if (typeof (input2alarm) != 'undefined') {
                if (!input2alarm) {
                    hasEmergencyAlarm = false;
                }
                else
                    hasEmergencyAlarm = true;
            }
            else
                hasEmergencyAlarm = true;
            break;
        case EnumAlarmType.ButtonC_Pressed_Input3_Active:
        case EnumAlarmType.ButtonC_Released_Input3_InActive:
            if (typeof (input3alarm) != 'undefined') {
                if (!input3alarm) {
                    hasEmergencyAlarm = false;
                }
                else
                    hasEmergencyAlarm = true;
            }
            else
                hasEmergencyAlarm = true;
            break;
        case EnumAlarmType.Input4_Active:
        case EnumAlarmType.Input4_InActive:
            if (typeof (input4alarm) != 'undefined') {
                if (!input4alarm) {
                    hasEmergencyAlarm = false;
                }
                else
                    hasEmergencyAlarm = true;
            }
            else
                hasEmergencyAlarm = true;
            break;
        case EnumAlarmType.Input5_Active:
        case EnumAlarmType.Input5_InActive:
            if (typeof (input5alarm) != 'undefined') {
                if (!input5alarm) {
                    hasEmergencyAlarm = false;
                }
                else
                    hasEmergencyAlarm = true;
            }
            else
                hasEmergencyAlarm = true;
            break;
        default:
            hasEmergencyAlarm = false;
            break;
    }
    return hasEmergencyAlarm;
}

function createCommonMapWindow(txttitle, width, height, closable, minbox, maxbox, toolbar) {
    var tmpwin;
    if (meimaptype == 0) {
        if (toolbar) {
            tmpwin = new Ext.ux.GMapWindow({
                title: txttitle,
                closable: closable,
                width: width,
                height: height,
                minimizable: minbox,
                maximizable: maxbox,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                tbar: toolbar,
                listeners: {
                    'minimize': function() {
                        if (minbox)
                            addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
        else {
            tmpwin = new Ext.ux.GMapWindow({
                title: txttitle,
                closable: closable,
                width: width,
                height: height,
                minimizable: minbox,
                maximizable: maxbox,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                listeners: {
                    'minimize': function() {
                        if (minbox)
                            addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
    }
    else if (meimaptype == 1) {
        if (toolbar) {
            tmpwin = new Ext.ux.BMapWindow({
                title: txttitle,
                closable: closable,
                width: width,
                height: height,
                minimizable: minbox,
                maximizable: maxbox,
                plain: true,
                x: nextwindowx,
                y: nextwindowy,
                tbar: toolbar,
                listeners: {
                    'minimize': function() {
                        if (minbox)
                            addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
        else {
            tmpwin = new Ext.ux.BMapWindow({
                title: txttitle,
                closable: closable,
                width: width,
                height: height,
                minimizable: minbox,
                maximizable: maxbox,
                plain: true,
                x: nextwindowx,
                y: nextwindowy,
                listeners: {
                    'minimize': function() {
                        if (minbox)
                            addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
    }
    else if (meimaptype == 2) {
        if (toolbar) {
            tmpwin = new Ext.ux.MMapWindow({
                title: txttitle,
                closable: closable,
                width: width,
                height: height,
                minimizable: minbox,
                maximizable: maxbox,
                plain: true,
                x: nextwindowx,
                y: nextwindowy,
                tbar: toolbar,
                listeners: {
                    'minimize': function() {
                        if (minbox)
                            addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
        else {
            tmpwin = new Ext.ux.MMapWindow({
                title: txttitle,
                closable: true,
                width: width,
                height: height,
                minimizable: minbox,
                maximizable: maxbox,
                plain: true,
                x: nextwindowx,
                y: nextwindowy,
                listeners: {
                    'minimize': function() {
                        if (minbox)
                            addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
    }
    else if (meimaptype == 3) {
        if (toolbar) {
            tmpwin = new Ext.ux.GMapWindowV3({
                title: txttitle,
                closable: closable,
                width: width,
                height: height,
                minimizable: minbox,
                maximizable: maxbox,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                tbar: toolbar,
                listeners: {
                    'minimize': function() {
                        if (minbox)
                            addTaskButtonForWindow(tmpwin);
                    }
                }


            });
        }
        else {
            tmpwin = new Ext.ux.GMapWindowV3({
                title: txttitle,
                closable: closable,
                width: width,
                height: height,
                minimizable: minbox,
                maximizable: maxbox,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                listeners: {
                    'minimize': function() {
                        if (minbox)
                            addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
    }
    else if (meimaptype == 4) {
        if (toolbar) {
            tmpwin = new Ext.ux.QMapWindow({
                title: txttitle,
                closable: closable,
                width: width,
                height: height,
                minimizable: minbox,
                maximizable: maxbox,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                tbar: toolbar,
                listeners: {
                    'minimize': function() {
                        if (minbox)
                            addTaskButtonForWindow(tmpwin);
                    }
                }


            });
        }
        else {
            tmpwin = new Ext.ux.QMapWindow({
                title: txttitle,
                closable: closable,
                width: width,
                height: height,
                minimizable: minbox,
                maximizable: maxbox,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                listeners: {
                    'minimize': function() {
                        if (minbox)
                            addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
    }
    return tmpwin;
}


function createHistoryMapWindow(txttitle, toolbar) {
    var tmpwin;
    if (meimaptype == 0) {
        if (toolbar) {
            tmpwin = new Ext.ux.GMapWindow({
                title: txttitle,
                closable: true,
                width: 500,
                height: 450,
                minimizable: true,
                maximizable: true,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                tbar: toolbar,
                listeners: {
                    'minimize': function() {
                        addTaskButtonForWindow(tmpwin);
                    }
                }


            });
        }
        else {
            tmpwin = new Ext.ux.GMapWindow({
                title: txttitle,
                closable: true,
                width: 500,
                height: 450,
                minimizable: true,
                maximizable: true,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                listeners: {
                    'minimize': function() {
                        addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
    }
    else if (meimaptype == 1) {
        if (toolbar) {
            tmpwin = new Ext.ux.BMapWindow({
                title: txttitle,
                closable: true,
                width: 500,
                height: 450,
                minimizable: true,
                maximizable: true,
                plain: true,
                x: nextwindowx,
                y: nextwindowy,
                tbar: toolbar,
                listeners: {
                    'minimize': function() {
                        addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
        else {
            tmpwin = new Ext.ux.BMapWindow({
                title: txttitle,
                closable: true,
                width: 500,
                height: 450,
                minimizable: true,
                maximizable: true,
                plain: true,
                x: nextwindowx,
                y: nextwindowy,
                listeners: {
                    'minimize': function() {
                        addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
    }
    else if (meimaptype == 2) {
        if (toolbar) {
            tmpwin = new Ext.ux.MMapWindow({
                title: txttitle,
                closable: true,
                width: 500,
                height: 450,
                minimizable: false,
                maximizable: true,
                plain: true,
                x: nextwindowx,
                y: nextwindowy,
                tbar: toolbar
            });
        }
        else {
            tmpwin = new Ext.ux.MMapWindow({
                title: txttitle,
                closable: true,
                width: 500,
                height: 450,
                minimizable: false,
                maximizable: true,
                plain: true,
                x: nextwindowx,
                y: nextwindowy
            });
        }
    }
    else if (meimaptype == 3) {
        if (toolbar) {
            tmpwin = new Ext.ux.GMapWindowV3({
                title: txttitle,
                closable: true,
                width: 500,
                height: 450,
                minimizable: true,
                maximizable: true,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                tbar: toolbar,
                listeners: {
                    'minimize': function() {
                        addTaskButtonForWindow(tmpwin);
                    }
                }


            });
        }
        else {
            tmpwin = new Ext.ux.GMapWindowV3({
                title: txttitle,
                closable: true,
                width: 500,
                height: 450,
                minimizable: true,
                maximizable: true,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                listeners: {
                    'minimize': function() {
                        addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
    }
    else if(meimaptype == 4){
        if (toolbar) {
            tmpwin = new Ext.ux.QMapWindow({
                title: txttitle,
                closable: true,
                width: 500,
                height: 450,
                minimizable: true,
                maximizable: true,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                tbar: toolbar,
                listeners: {
                    'minimize': function() {
                        addTaskButtonForWindow(tmpwin);
                    }
                }


            });
        }
        else {
            tmpwin = new Ext.ux.QMapWindow({
                title: txttitle,
                closable: true,
                width: 500,
                height: 450,
                minimizable: true,
                maximizable: true,
                plain: true,
                x: nextwindowx, //defined in paneldevicelist.js
                y: nextwindowy,
                listeners: {
                    'minimize': function() {
                        addTaskButtonForWindow(tmpwin);
                    }
                }
            });
        }
    }
    return tmpwin;
}
    
function getValidString(bol) {
    if (bol)
        return _TrackerMain_Valid;
    else
        return _TrackerMain_Invalid;
}

function getBooleanString(bol) {
    if (bol)
        return _TrackerMain_Yes;
    else
        return _TrackerMain_No;
}

function getDirectionString(direction) {
    var dirText = "";
   
    if (direction == "North") {
        dirText = _Direction_North;
    }
    else if (direction == "East") {
        dirText = _Direction_East;
    }
    else if (direction == "South") {
        dirText = _Direction_South;
    }
    else if (direction == "West") {
        dirText = _Direction_West;
    }
    else {
        dirText = direction;
    }
//    if (direction >= 337.5 || direction < 22.5) {
//        dirText = _Direction_North;
//    }
//    else if (direction >= 22.5 && direction < 67.5) {
//        dirText = _Direction_NorthEast;
//    }
//    else if (direction >= 67.5 && direction < 112.5) {
//        dirText = _Direction_East;
//    }
//    else if (direction >= 112.5 && direction < 157.5) {
//        dirText = _Direction_SouthEast;
//    }
//    else if (direction >= 157.5 && direction < 202.5) {
//        dirText = _Direction_South;
//    }
//    else if (direction >= 202.5 && direction < 247.5) {
//        dirText = _Direction_SouthWest;
//    }
//    else if (direction >= 247.5 && direction < 292.5) {
//        dirText = _Direction_West;
//    }
//    else if (direction >= 292.5 && direction < 337.5) {
//        dirText = _Direction_NorthWest;
//    }
    return dirText;

}

/*格式化时间*/
function formatTime(totalseconds) {
    var days = parseInt(totalseconds / (3600 * 24));
    var hours = parseInt((totalseconds % (3600 * 24)) / 3600);
    var minutes = parseInt((totalseconds % 3600) / 60);
    var seconds = parseInt(totalseconds % 60);

    var formattedtime = days.toString() + _TrackerMain_day + hours.toString() + ":" + minutes.toString() + ":" + seconds.toString();
    return formattedtime;
}


function createAlarmMapWindow(txttitle) {
    if (meimaptype == 0) {
        var tmpwin = new Ext.ux.GMapWindow({
            title: txttitle,
            closable: true,
            width: 500,
            height: 450,
            minimizable: false,
            plain: true,
            x: nextwindowx, //defined in paneldevicelist.js
            y: nextwindowy
        });
        return tmpwin;
    }
    else if (meimaptype == 1) {
        var tmpwin = new Ext.ux.BMapWindow({
            title: txttitle,
            closable: true,
            width: 500,
            height: 450,
            minimizable: false,
            plain: true,
            x: nextwindowx, //defined in paneldevicelist.js
            y: nextwindowy
        });
        return tmpwin;
    }
    else if (meimaptype == 2) {
        var tmpwin = new Ext.ux.MMapWindow({
            title: txttitle,
            closable: true,
            width: 500,
            height: 450,
            minimizable: false,
            plain: true,
            x: nextwindowx, //defined in paneldevicelist.js
            y: nextwindowy
        });
        return tmpwin;
    }
    else if(meimaptype == 3) {
        var tmpwin = new Ext.ux.GMapWindowV3({
            title: txttitle,
            closable: true,
            width: 500,
            height: 450,
            minimizable: false,
            plain: true,
            x: nextwindowx, //defined in paneldevicelist.js
            y: nextwindowy
        });
        return tmpwin;
    }
    else if(meimaptype == 4) {
        var tmpwin = new Ext.ux.QMapWindow({
            title: txttitle,
            closable: true,
            width: 500,
            height: 450,
            minimizable: false,
            plain: true,
            x: nextwindowx, //defined in paneldevicelist.js
            y: nextwindowy
        });
        return tmpwin;
    }
}


/*kilometer to miles
*/
function kilos2miles(kilos) {

    return (parseFloat(kilos) * 0.6213712).toFixed(2);
}


function miles2kilos(miles) {
    return (parseFloat(miles) * 1.609344).toFixed(2);
}

function getTrackerCheckboxCombo(multi,usenameasvalue) {
    this.combostore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: 'HandlerSearchTrackerName',
            timeout: 240000
        }),
        reader: new Ext.data.JsonReader({
            fields: [{ name: 'trackname' }, { name: 'snid'}],
            root: "data"
        })
    });

    this.combostore.load();

    this.combo;
    this.vfield = 'snid';
    if (usenameasvalue) {
        this.vfield = 'trackname';
    }
    if (multi) {
        this.combo = new Ext.ux.form.CheckboxCombo({
            name: 'trackname_combox',
            store: this.combostore,
            mode: 'local',
            displayField: 'trackname',
            width: 200,
            valueField: this.vfield,
            enableKeyEvents: true,
            fieldLabel: _ImageButtonText_TrackerName,
            editable: true
        });

        this.combo.on('keyup', function(obj) {
            obj.store.filter('trackname', obj.getRawValue(), true, false);
            obj.bindStore(obj.store);
        });

        this.combo.on('blur', function(obj) {
            obj.store.clearFilter();
            obj.bindStore(obj.store);
        });
    }
    else {
        this.combo = new Ext.form.ComboBox({
            name: 'trackname_combox',
            store: this.combostore,
            mode: 'local',
            displayField: 'trackname',
            width: 200,
            valueField: this.vfield,
            enableKeyEvents: true,
            fieldLabel: _ImageButtonText_TrackerName,
            editable: true
        });
    }
    return this.combo;
}



function getFenceCheckboxCombo(multi) {
    var fencestore = new Ext.data.Store({
        proxy: new Ext.data.HttpProxy({
            url: 'HandlerSearchPolygonFence',
            timeout: 240000
        }),
        reader: new Ext.data.JsonReader({
            fields: [{ name: 'polygon_geofence_id' }, { name: 'name'}],
            root: "data"
        })
    });

    fencestore.load();
    var fenceCombo;

    if (multi) {
        fenceCombo = new Ext.ux.form.CheckboxCombo({
            name: 'fence_combox',
            store: fencestore,
            mode: 'local',
            displayField: 'name',
            width: 300,
            valueField: 'polygon_geofence_id',
            enableKeyEvents: true,
            fieldLabel: _TxtGeofenceName,
            editable: true
        });

        fenceCombo.on('keyup', function() {
            fencestore.filter('polygon_geofence_id', fenceCombo.getRawValue(), true, false);
            fenceCombo.bindStore(fencestore);
        });

        fenceCombo.on('blur', function() {
            fencestore.clearFilter();
            fenceCombo.bindStore(fencestore);
        });
    }
    else {
        fenceCombo = new Ext.form.ComboBox({
            name: 'fence_combox',
            store: fencestore,
            mode: 'local',
            displayField: 'name',
            width: 300,
            valueField: 'polygon_geofence_id',
            enableKeyEvents: true,
            fieldLabel: _TxtGeofenceName,
            editable: true
        });
    }
    return fenceCombo;
}



function getPolygonAlarmTypeByIndex(index) {
    switch (index) {
        case 0:
            return _TxtNoneAlarm;
        case 1:
            return _TxtInAlarm;
        case 2:
            return _TxtOutAlarm;
        case 3:
            return _TxtInOutAlarm;
        default:
            return "";
    }
}



function replacechr(str, index, newchar) {
    var part1 = str.substr(0, index);
    var part2 = str.substr(index + 1, str.length);
    return part1 + newchar + part2;
}

function isUnicode(str) {
    var reg = new RegExp("[\u3000-\u9ffe]+");
    return (str.search(reg)>=0);
}

function padLeft(str, pad, count) {
    while (str.length < count)
        str = pad + str;
    return str;
}

function padRight(str,pad,count){
    while(str.length<count)
        str = str + pad;
    return str;
}

function toUnicode(s) {
    var len = s.length;
    var rs = "";
    for (var i = 0; i < len; i++) {
        var k = s.substring(i, i + 1);
        var c = s.charCodeAt(i);

        var shex = padLeft(c.toString(16), '0', 4);
        rs += shex;
    }
    return rs;
}


function changeArrayToString(array) {
    var str = "";
    for (var i = 0; i < array.length; i++) {
        if (i == 0)
            str = array[i];
        else
            str += "," + array[i];
    }
    return str;
}

function Celsius2Fahrenheit(v){
    return  v*1.8+32;
}

function Fahrenheit2Celsius(v){
    return (v-32)/1.8;
}

Date.prototype.format = function(format) {
    /*
    * eg:format="YYYY-MM-dd hh:mm:ss";
    */
    var o = {
        "M+": this.getMonth() + 1,  //month
        "d+": this.getDate(),     //day
        "h+": this.getHours(),    //hour
        "m+": this.getMinutes(),  //minute
        "s+": this.getSeconds(), //second
        "q+": Math.floor((this.getMonth() + 3) / 3),  //quarter
        "S": this.getMilliseconds() //millisecond
    }

    if (/(y+)/.test(format)) {
        format = format.replace(RegExp.$1, (this.getFullYear() + "").substr(4 - RegExp.$1.length));
    }

    for (var k in o) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1 ? o[k] : ("00" + o[k]).substr(("" + o[k]).length));
        }
    }
    return format;
}
